import Collapse from 'components/Markdown/Collapse'

export const meta = {
  title: 'GraphQL Requests (Go)',
  position: 100,
  technology: "go",
  technologyOrder: 3,
  articleGroup: "GraphQL Requests",
}

## Overview

The Prisma client lets you send GraphQL queries and mutations directly to your Prisma service using the `GraphQL` method:

```go
GraphQL(query string, variables map[string]interface{}) (map[string]interface{}, error)
```

As the GraphQL operation is passed untyped (as a regular string), the type returned is `map[string]interface{}`

### Examples

_Fetching a single user_:

```go
query := `
  query {
    user(id: "cjcdi63j80adw0146z7r59bn5") {
      id
      name
    }
  }
`

result := client.GraphQL(query, nil)
// sample result:
// map[data:[map[user:[map[id:cjcdi63j80adw0146z7r59bn5 name:Sarah]]]]]
```


_Fetching a single user using variables_:

```go
query := `
  query ($id: ID!){
    user(id: $id) {
      id
      name
    }
  }
`

variables := map[string]interface{}{
  "id": "cjcdi63j80adw0146z7r59bn5",
}

result := client.GraphQL(query, variables)
// sample result:
// map[data:[map[user:[map[id:cjcdi63j80adw0146z7r59bn5 name:Sarah]]]]]
```

_Creating a new user_:

```go
mutation := `
  mutation ($name: String!){
    createUser(name: $name) {
      id
      name
    }
  }
`

variables := map[string]interface{}{ "name": "Alice" }

result := client.GraphQL(mutation, variables)

// sample result:
// map[data:[map[createUser:[map[id:cjlhqfbfa003t0a23rhzjragl name:Alice]]]]]
```
